
SELECT Table0.emp_number AS col1,
CONCAT(Table0.emp_lastname, ' ', Table0.emp_middle_name, ' ', Table0.emp_firstname) AS col2,
Table2.empAmount AS col3,
Table3.Salary AS col4
FROM
hre_employee AS Table0
LEFT OUTER JOIN
(
    SELECT emp.emp_number, (com.amount * empCom.kpi / Table1.TotalKpi) AS empAmount
    FROM hre_employee AS emp, hre_compensation AS com, hre_emp_compensation AS empCom,
    (
        SELECT SUM(empCom.kpi) AS TotalKpi, empCom.year, empCom.month
        FROM hrentry_db.hre_emp_compensation AS empCom
        WHERE
        empCom.year = 2013
        AND empCom.month = 3
        GROUP BY empCom.year, empCom.month
    ) AS Table1
    WHERE
    empCom.year = Table1.year
    AND empCom.month = Table1.month
    AND emp.emp_number = empCom.emp_number
    AND com.year = Table1.year
    AND com.month = Table1.month
    AND emp.is_deleted = 0
) AS Table2 ON Table0.emp_number = Table2.emp_number
LEFT OUTER JOIN
(
    SELECT empSal.emp_number, SUM(empSal.ebsal_basic_salary) AS Salary
    FROM hrentry_db.hre_emp_basicsalary AS empSal
    GROUP BY empSal.emp_number
) AS Table3
ON Table0.emp_number = Table3.emp_number
WHERE Table0.is_deleted = 0